<?php
/**
 * Created by PhpStorm.
 * User: C。
 * Date: 2019/8/13
 * Time: 9:04
 */
namespace app\home\controller;

use app\common\model\Music as MusicModel;
use app\common\model\MusicCate as MusicCateModel;
use app\common\model\VideoCate as VideoCateModel;
use app\common\model\Video as VideoModel;

/**
 * 分类控制器
 * Class Oneclass
 * @package app\home\controller
 */
class Oneclass extends Base
{
    /**
     * [index  禅悦佛片列表]
     * @param type 3佛片 4佛乐
     * @return json
     * @author [C。]
     */
    public function index()
    {
        $param = input('param.');
        $musiccatemodel = new MusicCateModel();
        $musicmodel = new MusicModel();
        $videocatemodel = new VideoCateModel();
        $videomodel = new VideoModel();
        try{
            if($param['type'] == 3){
                $cate = $videocatemodel->getConditionByFields(['class_id'=>3,'states'=>1],'id,cname');
                foreach ($cate as &$v){
                    $video = $videomodel->getlists(['states'=>1,'itemid'=>$v['id']],0,2);
                    foreach($video as &$v1){
                        $http = substr($v1['img'],0,4);
                        if($http != 'http'){
                            $v1['img'] = config('domain_name').$v1['img'];
                        }
                        $http1 = substr($v1['url'],0,4);
                        if($http1 != 'http'){
                            $v1['url'] = config('domain_name').$v1['url'];
                        }
                        $v1['addtime'] = date('Y-m-d',$v1['addtime']);
                    }
                    $v['list'] = $video;
                }
            }elseif($param['type'] == 4){
                $cate = $musiccatemodel->getConditionByFields(['class_id'=>4,'states'=>1],'id,cname');
                foreach ($cate as &$v){
                    if($v['id'] == 3){
                        $size = 3;
                    }else{
                        $size = 6;
                    }
                    $music = $musicmodel->getlists(['states'=>1,'itemid'=>$v['id']],0,$size);
                    foreach($music as &$v1){
                        $http = substr($v1['img'],0,4);
                        if($http != 'http'){
                            $v1['img'] = config('domain_name').$v1['img'];
                        }
                        $http1 = substr($v1['url'],0,4);
                        if($http1 != 'http'){
                            $v1['url'] = config('domain_name').$v1['url'];
                        }
                    }
                    $v['list'] = $music;
                }
            }
        }catch(\Exception $e){
            systembug($e->getMessage(),2,$this->url);
            return admin_json(-1, '获取失败'.$e->getMessage());
        }
        return admin_json(1, '获取成功',$cate);
    }
}